package com.hzlx.consumption.controller;

import java.util.List;
import java.io.IOException;


import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.consumption.domain.MesMaintenancePartConsumption;
import com.hzlx.consumption.service.IMesMaintenancePartConsumptionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 维护备件消耗记录（跟踪维护任务中的物料使用情况）Controller
 * 
 * @author ruoyi
 * @date 2025-06-30
 */
@RestController
@RequestMapping("/equipment")
public class MesMaintenancePartConsumptionController extends BaseController
{

    @Autowired
    private IMesMaintenancePartConsumptionService mesMaintenancePartConsumptionService;

    /**
     * 查询维护备件消耗记录（跟踪维护任务中的物料使用情况）列表
     */
    @RequiresPermissions("equipment-service:consumption:list")
    @GetMapping("/consumption/list")
    public TableDataInfo list(MesMaintenancePartConsumption mesMaintenancePartConsumption)
    {
        startPage();
        List<MesMaintenancePartConsumption> list = mesMaintenancePartConsumptionService.selectMesMaintenancePartConsumptionList(mesMaintenancePartConsumption);
        return getDataTable(list);
    }

    /**
     * 导出维护备件消耗记录（跟踪维护任务中的物料使用情况）列表
     */
    @RequiresPermissions("equipment-service:consumption:export")
    @Log(title = "维护备件消耗记录（跟踪维护任务中的物料使用情况）", businessType = BusinessType.EXPORT)
    @PostMapping("/consumption/export")
    public void export(HttpServletResponse response, MesMaintenancePartConsumption mesMaintenancePartConsumption)
    {
        List<MesMaintenancePartConsumption> list = mesMaintenancePartConsumptionService.selectMesMaintenancePartConsumptionList(mesMaintenancePartConsumption);
        ExcelUtil<MesMaintenancePartConsumption> util = new ExcelUtil<MesMaintenancePartConsumption>(MesMaintenancePartConsumption.class);
        util.exportExcel(response, list, "维护备件消耗记录（跟踪维护任务中的物料使用情况）数据");
    }

    /**
     * 获取维护备件消耗记录（跟踪维护任务中的物料使用情况）详细信息
     */
    @RequiresPermissions("equipment-service:consumption:query")
    @GetMapping(value = "/consumption/{consumptionId}")
    public AjaxResult getInfo(@PathVariable("consumptionId") Long consumptionId)
    {
        return success(mesMaintenancePartConsumptionService.selectMesMaintenancePartConsumptionByConsumptionId(consumptionId));
    }

    /**
     * 新增维护备件消耗记录（跟踪维护任务中的物料使用情况）
     */
    @RequiresPermissions("equipment-service:consumption:add")
    @Log(title = "维护备件消耗记录（跟踪维护任务中的物料使用情况）", businessType = BusinessType.INSERT)
    @PostMapping("/consumption")
    public AjaxResult add(@RequestBody MesMaintenancePartConsumption mesMaintenancePartConsumption)
    {
        return toAjax(mesMaintenancePartConsumptionService.insertMesMaintenancePartConsumption(mesMaintenancePartConsumption));
    }

    /**
     * 修改维护备件消耗记录（跟踪维护任务中的物料使用情况）
     */
    @RequiresPermissions("equipment-service:consumption:edit")
    @Log(title = "维护备件消耗记录（跟踪维护任务中的物料使用情况）", businessType = BusinessType.UPDATE)
    @PutMapping("/consumption")
    public AjaxResult edit(@RequestBody MesMaintenancePartConsumption mesMaintenancePartConsumption)
    {
        return toAjax(mesMaintenancePartConsumptionService.updateMesMaintenancePartConsumption(mesMaintenancePartConsumption));
    }

    /**
     * 删除维护备件消耗记录（跟踪维护任务中的物料使用情况）
     */
    @RequiresPermissions("equipment-service:consumption:remove")
    @Log(title = "维护备件消耗记录（跟踪维护任务中的物料使用情况）", businessType = BusinessType.DELETE)
	@DeleteMapping("/consumption/{consumptionIds}")
    public AjaxResult remove(@PathVariable Long[] consumptionIds)
    {
        return toAjax(mesMaintenancePartConsumptionService.deleteMesMaintenancePartConsumptionByConsumptionIds(consumptionIds));
    }
}
